package com.banciyuan.bcywebview.biz.main.group.hot.viewholder;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.biz.groupdetail.NewTeamDetailActivity;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import de.greenrobot.daoexample.model.Team;

/**
 * Created by squall on 2017/4/21.
 */

public class ViewGroupBig extends ViewGroupBase {

    public ImageView imgBig;

    public ViewGroupBig(View convertView) {
        super(convertView);
        imgBig = (ImageView) convertView.findViewById(R.id.img_big);
    }

    public void renderData(final Context mContext, ViewGroupBig viewGroupBig, final Team team, int type) {
        super.renderGroupTagData(mContext, viewGroupBig.tag_text, viewGroupBig.workForm, team);
        setPostNum(viewGroupBig, team, type);
        if (!TextUtils.isEmpty(team.getName())) {
            viewGroupBig.title.setText(Html.fromHtml(team.getName()));
        }
        if (type == 0) {
            if (team.getPosts() != null && !team.getPosts().isEmpty()) {
                viewGroupBig.bestPost.setVisibility(View.VISIBLE);
                viewGroupBig.bestPost.setText(Html.fromHtml(team.getPosts().get(0).getPlain()));
            } else {
                viewGroupBig.bestPost.setVisibility(View.GONE);
            }
        } else {
            viewGroupBig.bestPost.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(team.getImg_src())) {
            viewGroupBig.imgBig.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(team.getImg_src(), viewGroupBig.imgBig, ImageOptions.options);
        } else {
            viewGroupBig.imgBig.setVisibility(View.GONE);
        }
        ((View) (viewGroupBig.title.getParent())).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoUtil.gotoAct(mContext, NewTeamDetailActivity.class, team.getGid(), team.getName());
            }
        });
    }

    private void setPostNum(ViewGroupBig viewGroupBig, Team team, int type) {
        if (type == 0 || type == -1) {
            viewGroupBig.post_num.setText(joinFormat);
        } else {
            viewGroupBig.post_num.setText(String.format(joinGroupFormat, team.getPost_num()));
        }
    }

}
